<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="/wK2un11/houtai/lib/layui/css/layui.css" />
</head>
<body>
	<form class="layui-form">

		<div class="layui-form-item">
			<label class="layui-form-label">婚纱名称</label>
			<div class="layui-input-block">
				<input type="text" name="proName" required lay-verify="required"
					placeholder="请输入婚纱名称" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">与♡ 卿婚纱公司地址</label>
			<div class="layui-input-block">
				<input type="text" name="proMateral" required lay-verify="required"
					placeholder="请输入与♡ 卿婚纱公司地址" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">设计元素</label>
			<div class="layui-input-block">
				<input type="text" name="yuanSu" required lay-verify="required"
					placeholder="请输入设计元素" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">婚纱售价(数字)</label>
			<div class="layui-input-block">
				<input type="text" name="salePrice" required lay-verify="required"
					placeholder="请输入婚纱售价" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">市场价(数字)</label>
			<div class="layui-input-block">
				<input type="text" name="marketPrice" required lay-verify="required"
					placeholder="请输入市场价" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">品牌</label>
			<div class="layui-input-block">
				<input type="text" name="brand" required lay-verify="required"
					placeholder="请输入品牌名" autocomplete="off" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">是否组装</label>
			<div class="layui-input-block">
				<select name="zuZhuang" lay-verify="required">
					<option value="Yes">Yes</option>
					<option value="No">No</option>
				</select>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">是否可定制</label>
			<div class="layui-input-block">
				<select name="dingZhi" lay-verify="required">
					<option value="Yes">Yes</option>
					<option value="No">No</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">型号</label>
			<div class="layui-input-block">
				<input type="text" name="model" required lay-verify="required"
					placeholder="请输入型号" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">颜色</label>
			<div class="layui-input-block">
				<input type="text" name="color" required lay-verify="required"
					placeholder="请输入颜色" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span> 图片地址</label>
				
				<div class="layui-input-inline">
					
            <button type="button" class="layui-btn" id="test1">
             <i class="layui-icon">&#xe67c;</i>上传图片
             </button>
				<img id="imgFace" style="width:120px" src="" />	
			<input name="picUrl" type="hidden" id="imgUrl"  class="layui-input">
				</div>
			</div>
		<div class="layui-form-item">
			<label class="layui-form-label">风格</label>
			<div class="layui-input-block">
				<input type="text" name="styles" required lay-verify="required"
					placeholder="请输入风格" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">款式</label>
			<div class="layui-input-block">
				<input type="text" name="kuanShi" required lay-verify="required"
					placeholder="请输入款式" autocomplete="off" class="layui-input">
			</div>
		</div>


		<div class="layui-form-item">
			<label class="layui-form-label">分类</label>
			<div class="layui-input-block">
				<select name="productTypeId" lay-verify="required">
					<c:forEach items="${typeList}" var="list">
						<option value="${list.id}">${list.productTypeName}</option>
					</c:forEach>
				</select>
			</div>
		</div>



		<div class="layui-form-item">
			<label class="layui-form-label">是否显示主页</label>
			<div class="layui-input-block">
				<select name="homeFlag" lay-verify="required">
					<option value="是">是</option>
					<option value="否">否</option>
				</select>
			</div>
		</div>




		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
			</div>
		</div>
	</form>
	<script type="text/javascript" src="/wK2un11/houtai/lib/layui/layui.js"></script>
		<script>
		//加载了layui的form模块
		layui.use(['form','upload'], function() {
			var form = layui.form;
			var $ = layui.jquery; //引入jquery
			  var upload = layui.upload;
			//执行实例
			  var uploadInst = upload.render({
			    elem: '#test1' //绑定元素
			    ,url: '/wK2un11/Houproduct_listServlet?method=upload' //上传接口
			    ,done: function(res){
			    	console.log(res);
			    	$("#imgUrl").val('upload/'+res.data);
			        $("#imgFace").attr('src','/wK2un9/upload/'+res.data);
			        
			    	//上传完毕回调
			    }
			    ,error: function(){
			      //请求异常回调
			    
			    }
			  });
				//监听提交
				form.on('submit(formDemo)', function(data) {
					var d = data.field; //表单中的数据，定义一个对象来接收
					//通过ajax向数据库提交数据了
					d.method="addDes";
					console.log(d); //提交之前的一个数据验证、通过打印的方式先手动的去判断一下这个数据
					var url ='/wK2un11/Houproduct_listServlet' ;
					//确保数据没有问题就进行ajax提交了
					$.post(url, d,
						function(data) {
							if(data.count>0){
								console.log('添加成功');
								var index=parent.layer.getFrameIndex(window.name); //获取当前窗口的name
             					 parent.layer.close(index);		//关闭窗口
							}
						}, "json");
					return false;
				});
			});
		</script>
</body>
</html>
